package com.ling.algorithm;

public class ThreadPoolTest {

    public static void main(String[] args) {
        syncwaitNotify();
    }

    public static void syncwaitNotify(){
        final Object o = new Object();
        char[] aI = "1234567".toCharArray();
        char[] aC = "ABCDEFG".toCharArray();

        new Thread(()->{
            synchronized (o){
                for (char c : aI) {
                    System.out.print(c);
                    try {
                        o.notify();
                        o.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }


            }

            o.notify();  //唤醒线程
        },"t1").start();

        new Thread(()->{
            synchronized (o){
                for (char c : aC) {
                    System.out.print(c);
                    try {
                        o.notify();
                        o.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }


            }

            o.notify();  //唤醒线程
        },"t2").start();
    }
}
